package com.zhuss.util;

import java.util.Date;
import java.util.HashMap;
import java.util.Set;

import com.cloopen.rest.sdk.CCPRestSmsSDK;

public class MessageUtil {
	
	
	
	public static void main(String[] args) {
		// sendMessage();
		
		sendMsg("18317100362", "1", "123655", "10");
		
		System.out.println(new Date());
	}
	
	
	@SuppressWarnings("unchecked")
	public static void sendMsg(String phone, String moduleId, String number, String minute) {
		HashMap<String, Object> result = null;

		CCPRestSmsSDK restAPI = new CCPRestSmsSDK();
		restAPI.init("app.cloopen.com", "8883");// 初始化服务器地址和端口，格式如下，服务器地址不需要写https://
		restAPI.setAccount("8a216da87206f2ec01720be12b640323", "e0c512fef0cc43c7a3eabef4d3dacf90");// 初始化主帐号和主帐号TOKEN
		restAPI.setAppId("8a216da87206f2ec01720be12bcc0329");// 初始化应用ID
		result = restAPI.sendTemplateSMS(phone, moduleId ,new String[]{number, minute});

		System.out.println("SDKTestSendTemplateSMS result=" + result);
		
		if("000000".equals(result.get("statusCode"))){
			//正常返回输出data包体信息（map）
			HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");
			Set<String> keySet = data.keySet();
			for(String key:keySet){
				Object object = data.get(key);
				System.out.println(key +" = "+object);
			}
		}else{
			//异常返回输出错误码和错误信息
			System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
		}
	}
	
	@SuppressWarnings("unchecked")
	public static void sendMessage() {
		HashMap<String, Object> result = null;

		CCPRestSmsSDK restAPI = new CCPRestSmsSDK();
		restAPI.init("app.cloopen.com", "8883");// 初始化服务器地址和端口，格式如下，服务器地址不需要写https://
		restAPI.setAccount("8a216da87206f2ec01720be12b640323", "e0c512fef0cc43c7a3eabef4d3dacf90");// 初始化主帐号和主帐号TOKEN
		restAPI.setAppId("8a216da87206f2ec01720be12bcc0329");// 初始化应用ID
		result = restAPI.sendTemplateSMS("18317100362", "1" ,new String[]{"10", "20"});

		System.out.println("SDKTestSendTemplateSMS result=" + result);
		
		if("000000".equals(result.get("statusCode"))){
			//正常返回输出data包体信息（map）
			HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");
			Set<String> keySet = data.keySet();
			for(String key:keySet){
				Object object = data.get(key);
				System.out.println(key +" = "+object);
			}
		}else{
			//异常返回输出错误码和错误信息
			System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
		}
	}

}
